package com.atguigu.spzx.model.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Author：tzl
 * @Date：2024/1/29 10:39
 * @description: mp时间加强，可自动添加更新时间和插入时间
 */
@Component
public class DateHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        // 设置createTime和updateTime为当前时间
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "isDeleted", Integer.class, 0);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // 设置updateTime为当前时间
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}
